package org.lc.stk.model.baseInfo;

import java.util.List;

import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;

@Entity
@Table(name = "department")
@Comment("部门")
@SQLDelete(sql = "UPDATE department SET is_deleted = true WHERE id = ?")
@Where(clause = "is_deleted = false")
public class Department {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(length = 100)
    @Comment("部门名称")
    private String name;

    @Column(unique = true, length = 50)
    @Comment("部门编码")
    private String code;

    @ManyToOne
    @JoinColumn(name = "parent_id")
    @Comment("上级部门")
    private Department parent;

    @ManyToOne
    @JoinColumn(name = "type_id")
    @Comment("部门类型")
    private DepartmentType type;

    @Column
    @Comment("排序号")
    private Integer orderNum = 0;

    @Column(length = 500)
    @Comment("备注")
    private String remark;

    @Column
    @Comment("是否已删除")
    private Boolean isDeleted = false;

    @Transient
    private List<Department> children;

    // Getters and Setters
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Department getParent() {
        return parent;
    }

    public void setParent(Department parent) {
        this.parent = parent;
    }

    public DepartmentType getType() {
        return type;
    }

    public void setType(DepartmentType type) {
        this.type = type;
    }

    public Integer getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Boolean getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(Boolean isDeleted) {
        this.isDeleted = isDeleted;
    }

    public List<Department> getChildren() {
        return children;
    }

    public void setChildren(List<Department> children) {
        this.children = children;
    }
}
